/* 
 * File:   Lecturer.cpp
 * Author: user
 * 
 * Created on July 26, 2014, 11:41 AM
 */

#include <iostream>
#include <sstream>
#include <iomanip>
#include <sqlite3.h>
#include "Lecturer.h"

const string sql_DB = "CSCI222_A2.db";
const string ExamTopic_table = "ExamTopic";
const string Question_table = "Question";
const string TestSummary_table = "TestSummary";

//Static vatiable
static bool _header;
static bool _displayCallBack;

static bool _isSelectExamTopic;
static int _selectedExamTopicID;
static string _selectedExamTopic_topic;
static string _selectedExamTopic_desc;
static bool _examTopicFound;
static vector<string> _examTopics; //all examTopic create by _userID

static bool _isSelectQuestion;
static int _selectedTestQuestionID;
static bool _questionFound;

static int _questionTable_viewType;

static bool _testSummaryFound;

//#define _debug

Lecturer::Lecturer(): User("",1) {
}

Lecturer::Lecturer(string userID) : User(userID,1) 
{
    _isSelectExamTopic = false;
    _selectedExamTopic_topic = "";
    _selectedExamTopic_desc = "";
    _selectedExamTopicID = 0;
    
    _isSelectQuestion = false;
    _questionTable_viewType = 0;
}

Lecturer::Lecturer(const Lecturer& orig) {
}

Lecturer::~Lecturer() {
}

void Lecturer::setExamTopic(ExamTopic examTopic)
{
    _examTopic = examTopic;
}

void Lecturer::printMenu()
{
    cout << endl;
    cout << "*****Lecturer menu*****" << endl;
    cout << "---------------------------------" << endl << endl ;
    cout << "1)     Add candidate" << endl;
    cout << "2)     Update candidate" << endl;
    cout << "3)     Delete candidate" << endl;
    cout << "4)     Show all candidate account" << endl;
    cout << "5)     Add examination topic" << endl;
    cout << "6)     Update examination topic" << endl;
    cout << "7)     Delete examination topic" << endl;
    cout << "8)     Show all examination topic" << endl;
    cout << "9)     View test summary" << endl;
    cout << "0)     Log out" << endl << endl;
    //cout << "0=99)     Quit program" << endl << endl;
}

bool Lecturer::menuAction(int iSelection,bool& isExitProgram, int& loginStatus)
{
    switch (iSelection)
    {
        case 0: //Log out
        {
            menuItemAction(LOG_OUT,isExitProgram,loginStatus);
            break;
        }
        case 1: //Add account
        {
            menuItemAction(ADD_ACCT,isExitProgram,loginStatus);  
            break;
        }
        case 2: //update account
        {
            menuItemAction(UPDATE_ACCT,isExitProgram,loginStatus); 
            break;
        }
        case 3: //delete account
        {
            menuItemAction(DEL_ACCT,isExitProgram,loginStatus);   
            break;
        }
        case 4: //show all account
        {
            displayAllUserAccount(_userID);
            break;
        }
        case 5: //Add examination topic
        {
            promptUserForAddingExamTopic();
            addExamTopic(_examTopic.getTopic(),_examTopic.getDesc(),_userID);
            promptUserForAddingQuestion2ExamTopic();
            addQuestion2ExamTopic();
            
            break;
        }
        case 6: //Update examination topic
        {
            string column;
            string newValue;
            if (!promptUserForUpdateExamTopic(column,newValue))
                break;
            if (column == "ExamTopic" || column == "Description")
                updateExamTopic(_examTopic.getID(),column,newValue,_userID);
            else
            {
                displayQuestion(_examTopic.getTopic(),1);
                
                if (promptUserForSelectingQuestion())
                {
                    displayQuestion(_examTopic.getTopic(),2);
                    if (_questionFound)
                    {
                        int questionID;
                        string column;
                        string newValue;
                        if (promptUserForUpdateQuestion(column,newValue))
                        {
                            updateQuestion(_examTopic.getSelectedQuestionID(), 
                                    column, newValue,_examTopic.getTopic());
                        }
                    }
                }
            }
                
            break;
        }
        case 7: //Delete examination topic
        {
            int topicID;
            if (promptUserForDeleteExamTopic())
                deleteExamTopic(_examTopic.getID(),_userID);
            break;
        }
        case 8: //Show all examination topic
        {
            system("clear");
            cout << "[-----Update examination topic-----]"<< endl;
            displayExamTopic(true);
            break;
        }
        case 9: //View test summary
        {
            system("clear");
            cout << "[-----Test Summary-----]"<< endl;
            extractTestSummary(_userID);
            break;
        }
    }
    return true;
}

bool Lecturer::displayExamTopic(bool queryQuestion)
{
    bool ret(true);
    _displayCallBack = true;
    _examTopicFound = false;
    _header = true;
    char * sql;
    sql = sqlite3_mprintf("SELECT * FROM %q WHERE CreateBy='%q';",
            ExamTopic_table.c_str(), _userID.c_str()); 
    
    ret = executeSql(sql,ExamTopic_table);
    
    _displayCallBack = false;
    _header = false;
    
    //Query Question
    if (queryQuestion && _examTopicFound)
    {
        _examTopicFound = false;

        if (promptUserForSelectingExamTopic() && !_examTopic.getTopic().empty())
            displayQuestion(_examTopic.getTopic(),0);
    }
    
    _displayCallBack = false;
    
    return true;
}

bool Lecturer::promptUserForSelectingExamTopic()
{  
    _isSelectExamTopic = true;
    bool valid(false);
    string strTopicID;
    int iSelectedID;
    while(!valid)
    {
        cout << endl << "Please select a TopicID: ";
        getline(cin, strTopicID);

        valid = validateIntInput(strTopicID, iSelectedID);
    }
    
    char * sql;
    _examTopicFound = false;
    sql = sqlite3_mprintf("SELECT * FROM %q WHERE ID='%d';",
        ExamTopic_table.c_str(), iSelectedID); 
    
    executeSql(sql,ExamTopic_table);
    
    if(!_examTopicFound)
    {
        cout << endl << "No exam topic found in database!!!" << endl; 
        _isSelectExamTopic = false;
        return false;
    }
    
    //set selected exam topic and description
    updateExamObject();
    
    _isSelectExamTopic = false;
    return true;
}

bool Lecturer::promptUserForSelectingQuestion()
{  
    bool valid(false);
    _isSelectQuestion = true;
    string strQuestionID;
    int iQuestionID;
    _questionFound = false;
    _displayCallBack = false;
    while(!valid)
    {
        cout << endl << "Please select a questions: ";
        getline(cin, strQuestionID);

        valid = validateIntInput(strQuestionID, iQuestionID);
    }
    
    char * sql;
    sql = sqlite3_mprintf("SELECT * FROM %q WHERE ID='%d' AND ExamTopic='%q';",
        Question_table.c_str(), iQuestionID,_examTopic.getTopic().c_str()); 
    
    executeSql(sql,Question_table);
    if(!_questionFound)
    {
        cout << endl << "No question found in database!!!" << endl; 
        _isSelectQuestion = false;
        return false;
    }
     
    //set selected exam topic and description
    updateExamObject();
    
    _isSelectQuestion = false;
    return true; 
}

//Display all Question under the Exam topic
//viewType = 0; show all test question under the exam topic
//viewType = 1; show all test question(only question column) under the exam topic
//viewType = 2; show selected test question under the exam topic
bool Lecturer::displayQuestion(string topic, int viewType)
{
    bool ret(true);
    _questionTable_viewType = viewType;
    _displayCallBack = true;
    _questionFound = false;
    _header = true;
    
    char * sql;
    if (viewType < 2) //all or only question
    {
        sql = sqlite3_mprintf("SELECT * FROM %q WHERE ExamTopic='%q';",
            Question_table.c_str(), topic.c_str()); 
    }
    else
    {
         sql = sqlite3_mprintf("SELECT * FROM %q WHERE ExamTopic='%q' AND ID='%d';",
            Question_table.c_str(), topic.c_str(),_examTopic.getSelectedQuestionID());
    }

    ret = executeSql(sql,Question_table);
    
    _displayCallBack = false;
    _header = false;
    
    return ret;
}

void Lecturer::promptUserForAddingExamTopic()
{
    system("clear");
    cout << "[-----Add examination topic-----]"<< endl;
    cout << "Please enter exam code: ";
    string topic;
    getline(cin, topic);

    cout << "Please enter exam description: ";
    string desc;
    getline(cin, desc);
    
    _examTopic.setTopic(topic);
    _examTopic.setDesc(desc);
}

bool Lecturer::addExamTopic(string topic,string desc,string createBy)
{
    if (topic.empty() || desc.empty())
    {
        cout << endl << endl << "Add exam topic failed!!!" << endl;
        cout << "Topic code and description field can't be empty" << endl;
        return false;
    }
    
    char * sqlInsert;
    sqlInsert = sqlite3_mprintf("INSERT INTO %q (ExamTopic,Description,CreateBy) VALUES ('%q', '%q', '%q');" ,
                  ExamTopic_table.c_str(), topic.c_str(),desc.c_str(),createBy.c_str());
    
    
    if (executeSql(sqlInsert,ExamTopic_table))
        cout << endl << "Add Exam topic successfully!!!" << endl;
    else
    {
        cout << "Add Exam topic failed!!!" << endl;
        return false;
    }
    return true;
    
}

void Lecturer::promptUserForAddingQuestion2ExamTopic()
{
    cout << "[-----Add MCQ Question-----]"<< endl;
    
    vector<string> selections;
    for (int i = 0 ; i < 5 ;i++)
    {
        char num = i+49;
        selections.clear();
        cout << "Please enter question" << num << ": ";
        string question;
        getline(cin, question);

        for (int j = 0 ;j < 4; j++)
        {
            string mcq;
            char choice = j+97;
            cout << "Please enter choice(" << choice << "): ";
            getline(cin, mcq);

            selections.push_back(mcq);
        }
        
        cout << "Please enter answer: ";
        string ans;
        getline(cin, ans);
  
        _examTopic.addQuestion(TestQuestion(question,selections,ans));
        cout << endl;
    }
}

bool Lecturer::addQuestion2ExamTopic()
{
    if ( _examTopic.getQuestions().empty())
    {
        cout << endl << endl << "Add question failed!!!" << endl;
        cout << "Question field can't be empty" << endl;
        return false;
    }
    
    char * sqlInsert;
    vector<TestQuestion>::iterator this_q = _examTopic.getQuestions().begin();
    int count = 0;
    for (;this_q !=  _examTopic.getQuestions().end();++this_q)
    {
        count++;
        vector<string> my_mcq = this_q->getSelections();
        string t1 = my_mcq[0];
        t1 = my_mcq[1];
        t1 = my_mcq[2];
        t1 = my_mcq[3];
        sqlInsert = sqlite3_mprintf("INSERT INTO %q (Question,a,b,c,d,Answer,ExamTopic) VALUES ('%q','%q','%q','%q','%q','%q','%q');" ,
                  Question_table.c_str(),
                  this_q->getQuestion().c_str(),
                  my_mcq[0].c_str(),
                  my_mcq[1].c_str(),
                  my_mcq[2].c_str(),
                  my_mcq[3].c_str(),
                  this_q->getAns().c_str(),
                  _examTopic.getTopic().c_str());
    
        if (executeSql(sqlInsert, Question_table))
            cout << endl << "Add Question" << count << " successfully!!!" << endl;
        else
        {
            cout << "Add Question" << count << " failed!!!" << endl;
            return false;
        }
    }
    return true;
    
}

bool Lecturer::promptUserForUpdateExamTopic(string& column, string& newValue)
{
    system("clear");
    cout << "[-----Update examination topic-----]"<< endl;
    displayExamTopic();
    
    // no topic found which was created by current userID
    if(!_examTopicFound)
    {
        cout << endl << "No exam topic found in database!!!" << endl; 
        return false;
    }

    if (!promptUserForSelectingExamTopic())
        return false;
    
    bool valid(false);
    while(!valid)
    {
        cout << "[-----Update menu-----]" << endl;
        cout << "a)   Exam topic" << endl;
        cout << "b)   Exam description" << endl;
        cout << "c)   Test question" << endl << endl;
         
        cout << "Please select your choice: ";
        getline(cin, column);
        valid = true;
        if (column == "a")
            column = "ExamTopic";
        else if (column == "b")
            column = "Description";
        else if (column == "c")  // edit Question table
            column = "Question_table";
        else
        {
            cout << "Invalid input. Please enter a or b" << endl;
            valid = false;
        }
    }
    
    if (column == "ExamTopic" || column == "Description")
    {
        cout << "Enter new value: ";
        getline(cin, newValue);  
    }
    
    return true;
}

bool Lecturer::updateExamTopic(int topicID,string column, string newValue,string createBy)
{
    _displayCallBack = false;
    _examTopicFound = false;
    char * sqlSelect;
    sqlSelect = sqlite3_mprintf("SELECT * FROM %q WHERE CreateBy='%q' AND ID='%d'", 
            ExamTopic_table.c_str(), createBy.c_str(), topicID); 
    executeSql(sqlSelect,ExamTopic_table);
    if(!_examTopicFound)
    {
        cout << endl << "Exam topic not found in database!!!" << endl; 
        cout << "Update exam topic failed!!!" << endl;
        return false;
    }
    
    /* Create upate SQL statement for ExamTopic table*/
    char * sqlUpdate;
    sqlUpdate = sqlite3_mprintf("UPDATE %q set %q = '%q' WHERE CreateBy='%q'AND ID=='%d';",
                  ExamTopic_table.c_str(),column.c_str(), newValue.c_str(),createBy.c_str(),topicID);
    
    
    if (executeSql(sqlUpdate,ExamTopic_table))
    {
        cout << endl << "Update exam topic successfully!!!" << endl;
        if (column == "ExamTopic")
        {
           /* Create upate SQL statement for Question table*/
           char * sqlUpdate2;
           sqlUpdate2 = sqlite3_mprintf("UPDATE %q set %q = '%q' WHERE ExamTopic=='%q';",
                         Question_table.c_str(),column.c_str(), newValue.c_str(),_examTopic.getTopic().c_str());


           if (executeSql(sqlUpdate2,Question_table))
               cout << "Update question successfully!!!" << endl;
           else
           {
               cout << "Update question failed!!!" << endl;
               return false;
           }
        }
    }
    else
    {
        cout << endl << "Update exam topic failed!!!" << endl;
        return false;
    }
    
    return true;
}

bool Lecturer::promptUserForUpdateQuestion(string& column, string& newValue)
{
    // no topic found which was created by current userID
    if(!_questionFound)
    {
        cout << endl << "No exam topic found in database!!!" << endl; 
        return false;
    }
    
    bool valid(false);
    while(!valid)
    {
        cout << endl;
        cout << "[-----Update question menu-----]" << endl;
        cout << "a)   Question" << endl;
        cout << "b)   Choice (a)" << endl;
        cout << "c)   Choice (b)" << endl;
        cout << "d)   Choice (c)" << endl;
        cout << "e)   Choice (d)" << endl;
        cout << "f)   Answer" << endl << endl;
         
        cout << "Please select your choice: ";
        getline(cin, column);
        valid = true;
        if (column == "a")
            column = "Question";
        else if (column == "b")
            column = "a";
        else if (column == "c")
            column = "b";
        else if (column == "d")
            column = "c";
        else if (column == "e")
            column = "d";
        else if (column == "f")  // edit Question table
            column = "Answer";
        else
        {
            cout << "Invalid input. Please enter a - f" << endl;
            valid = false;
        }
    }
    
    cout << "Enter new value: ";
    getline(cin, newValue);  
    
    return true;
    
}

bool Lecturer::updateQuestion(int questionID, string column, string newValue,string examTopic)
{
    _displayCallBack = false;
    _questionFound = false;
    char * sqlSelect;
    sqlSelect = sqlite3_mprintf("SELECT * FROM %q WHERE ExamTopic='%q' AND ID='%d'", 
            Question_table.c_str(), examTopic.c_str(), questionID); 
    
    executeSql(sqlSelect,Question_table);
    if(!_questionFound)
    {
        cout << endl << "Question not found in database!!!" << endl; 
        cout << "Update question failed!!!" << endl;
        return false;
    }
    
    /* Create upate SQL statement for Question table*/
    char * sqlUpdate;
    sqlUpdate = sqlite3_mprintf("UPDATE %q set %q = '%q' WHERE ExamTopic='%q'AND ID=='%d';",
                  Question_table.c_str(),column.c_str(), newValue.c_str(),examTopic.c_str(),questionID);
    
    
    if (executeSql(sqlUpdate,Question_table))
        cout << endl << "Update question successfully!!!" << endl;
    else
    {
        cout << endl << "Update question failed!!!" << endl;
        return false;
    }
    
    return true;
    
}

bool Lecturer::promptUserForDeleteExamTopic()
{
    system("clear");
    cout << "[-----Delete examination topic-----]"<< endl;
    displayExamTopic();
    
    cout << endl << "Warning: All the questions under the selected exam topic will be deleted also" << endl;
    cout << "Do you want to continue? (Y/N): ";
    string ans;
    getline(cin, ans);
    while(ans!="Y" && ans != "N")
    {
        cout << "Invalid input!!!" << endl;
        cout << "Are you sure want to exit? (Y/N): ";
        getline(cin, ans);
    }
    if (ans == "N")
        return false;
    
    if (!promptUserForSelectingExamTopic())
        return false;
    
    return true;
}

bool Lecturer::deleteExamTopic(int topicID,string createBy)
{
    _displayCallBack = false;
    _examTopicFound = false;
    char * sqlSelect;
    sqlSelect = sqlite3_mprintf("SELECT * FROM %q WHERE CreateBy='%q' AND ID='%d'", 
            ExamTopic_table.c_str(), createBy.c_str(), topicID); 
    executeSql(sqlSelect,ExamTopic_table);
    if(!_examTopicFound)
    {
        cout << endl << "Exam topic not found in database!!!" << endl; 
        cout << "Delete exam topic failed!!!" << endl;
        return false;
    }
    
    /* Create delete exam SQL statement */
   char * sqlDel;
   sqlDel = sqlite3_mprintf("DELETE FROM %q WHERE CreateBy='%q' AND ID='%d';" ,
                  ExamTopic_table.c_str(), createBy.c_str(),topicID); 
    
    
    if (executeSql(sqlDel,ExamTopic_table))
        cout << endl << "Delete Exam topic successfully!!!" << endl;
    else
    {
        cout << endl << "Delete Exam topic failed!!!" << endl;
        return false;
    }
   
    /* Create delete question SQL statement */
   sqlDel = sqlite3_mprintf("DELETE FROM %q WHERE ExamTopic='%q';" ,
                  Question_table.c_str(), _examTopic.getTopic().c_str()); 
    
    
    if (executeSql(sqlDel,ExamTopic_table))
        cout << "Delete questions successfully!!!" << endl;
    else
    {
        cout << "Delete questions failed!!!" << endl;
        return false;
    }
    return true;
}

bool Lecturer::executeSql(const char* sql,string table) 
{
   sqlite3 *db;
   char *zErrMsg = 0;
   int rc;
   /* Open database */
   rc = sqlite3_open(sql_DB.c_str(), &db); 
   
   if( rc )
   {
      fprintf(stderr, "\n\nCan't open database: %s\n", sqlite3_errmsg(db));
      return false;
   }else{
      //fprintf(stderr, "Opened database successfully\n");
   }
           
   /* Execute SQL statement */
   if (table == ExamTopic_table)
       rc = sqlite3_exec(db, sql, querryCallBack_ExamTopic, 0, &zErrMsg);  
   else if (table == Question_table)
       rc = sqlite3_exec(db, sql, querryCallBack_Question, 0, &zErrMsg);  
   else //Test summary
       rc = sqlite3_exec(db, sql, querryCallBack_TestSummary, 0, &zErrMsg);  
   
   if( rc != SQLITE_OK )
   {
      fprintf(stderr, "\n\nSQL error: %s\n", zErrMsg);
      sqlite3_free(zErrMsg);
      return false;
   }else{
      //fprintf(stdout, "retrieve data successfully\n");
   }
 
   sqlite3_close(db);
   return true;
   
}

int Lecturer::querryCallBack_ExamTopic(void *data, int argc, char **argv, char **azColName)
{   
   if(_displayCallBack)
   {
        if (_header)
        {
         _header = false;
         cout << left << setw(10)
         << "TopicID" << left << setw(20)
         << "ExamTopic" << left << setw(80)
         << "Description";
   
#ifdef _debug
    cout << left << setw(20)
         << "CreateBy" << endl;
    cout << "----------------------------------------------------------------------------------------------------" << endl;
#else
    cout << endl;
    cout << "----------------------------------------------------------------------------------------------------" << endl;
#endif
        }
        cout << left << setw(10)
             << (argv[0] ? argv[0] : "NULL") << left << setw(20) 
             << (argv[1] ? argv[1] : "NULL") << left << setw(80) 
             << (argv[2] ? argv[2] : "NULL");
    
#ifdef _debug
    cout << left << setw(20)
         << (argv[3] ? argv[3] : "NULL") << endl;
#else
    cout << endl;
#endif

   }
   
   if (_isSelectExamTopic)
   {
       stringstream ss (argv[0]);
       ss >> _selectedExamTopicID;
    
       _selectedExamTopic_topic = (argv[1] ? argv[1] : "NULL");
       _selectedExamTopic_desc = (argv[2] ? argv[2] : "NULL");
       
       _examTopics.push_back(argv[1] ? argv[1] : "NULL");
   }
   _examTopicFound = true; 
   return 0;
}

int Lecturer::querryCallBack_Question(void *data, int argc, char **argv, char **azColName)
{
   if (_displayCallBack)
   {
       if (_questionTable_viewType == 0 || _questionTable_viewType == 2) //all
        {
            cout << endl; 
            for(int i=1; i<argc-1; i++) //hide the first and last column(ID,CreateBy)
            { 
               if (i==1) // print header 
               {
                   if (_questionTable_viewType == 0)
                       cout << "[-----Questions ID: " << (argv[0] ? argv[0] : "") << "-----]" << endl;
                   else
                       cout << "[-----Selected question ID: " << (argv[0] ? argv[0] : "") << "-----]" << endl;       
               }
               printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
            }
            //printf("\n");
        }
        else if (_questionTable_viewType == 1) //Question
        {   
            if (_header)
            {
                cout << "[-----All questions-----]"<< endl;
                _header = false;
                cout << left << setw(15)
                     << "Question ID" //<< left << setw(2048)
                     << "Description"  << endl
                     << "----------------------------------------------------------------------------------------------------" << endl;
            }

            cout << left << setw(15)
                  << (argv[0] ? argv[0] : "NULL") //<< left << setw(2048) 
                  << (argv[1] ? argv[1] : "NULL") << endl;

        }  
   }
   
   if (_isSelectQuestion)
   {
       stringstream ss (argv[0]);
       ss >> _selectedTestQuestionID;
    
   }
   _questionFound = true;
   return 0;
}

void Lecturer::updateExamObject()
{
    _examTopic.setID(_selectedExamTopicID);
    _examTopic.setTopic(_selectedExamTopic_topic);
    _examTopic.setDesc(_selectedExamTopic_desc);
    _examTopic.setSelectedQuestionID(_selectedTestQuestionID);
}

bool Lecturer::extractTestSummary(string _userID)
{   
    _displayCallBack = false;
    _examTopicFound = false;
    _header = false;
    _isSelectExamTopic = true;
    _examTopics.clear();
    char * sql;
    sql = sqlite3_mprintf("SELECT * FROM %q WHERE CreateBy='%q';",
            ExamTopic_table.c_str(), _userID.c_str()); 
    
    executeSql(sql,ExamTopic_table);
    if (!_examTopicFound)
    {
        cout << endl << "No test summary found in database!!!" << endl; 
        _isSelectExamTopic = false;
        return false;
    }
    _isSelectExamTopic = false;
    
    bool ret(true);
    _displayCallBack = true;
    _testSummaryFound = false;
    _header = true;
    
    stringstream condition;
    for (int i=0; i < _examTopics.size(); i++)
    {   if (i > 0)
            condition << " OR ";
        condition << "ExamTopic=" << '\'' << _examTopics[i] << '\'';
    }
    
    sql = sqlite3_mprintf("SELECT * FROM %q WHERE %s;",
            TestSummary_table.c_str(), condition.str().c_str()); 
    
    ret = executeSql(sql,TestSummary_table);
    if(!_testSummaryFound)
    {
        cout << endl << "No test summary found in database!!!" << endl; 
        return false;
    }
  
    _displayCallBack = false;
    
    return true;
}

int Lecturer::querryCallBack_TestSummary(void *data, int argc, char **argv, char **azColName)
{   
   if(_displayCallBack)
   {
        if (_header)
        {
            _header = false;
            cout << left << setw(30)
               << "ExamTopic" << left << setw(20)
               << "TakenBy" << left << setw(20)
               << "Result" << left << setw(15)
               << "TimeOfAttempt" << left << setw(20)
               << "DateTime" << endl;
            
            cout << "----------------------------------------------------------------------------------------------------" << endl;
        }
       
        cout << left << setw(30)
            << (argv[1] ? argv[1] : "NULL") << left << setw(20) 
            << (argv[2] ? argv[2] : "NULL") << left << setw(20) 
            << (argv[3] ? argv[3] : "NULL") << left << setw(15) 
            << (argv[4] ? argv[4] : "NULL") << left << setw(20) 
            << (argv[5] ? argv[5] : "NULL");
   }
  
   _testSummaryFound = true; 
   return 0;
}

